package com.huang.core.widget.viewpager.transform

import androidx.viewpager.widget.ViewPager
import android.view.View

class ScaleTranslationXOpciatPageTransformer : ViewPager.PageTransformer {
    private val defaultScale = 14f / 15f
    override fun transformPage(page: View, position: Float) {
        val width = 20f
        if (position < -1) { // [-Infinity,-1)
            page.scaleX = defaultScale
            page.scaleY = defaultScale
            page.translationX = width
            page.alpha = defaultScale
        } else if (position <= 0) { // [-1,0]
            page.scaleX = 1 + position / 15f
            page.scaleY = 1 + position / 15f
            page.translationX = (0 - position) * width
            page.alpha =  1 + position / 15f
        } else if (position <= 1) { // (0,1]
            page.scaleX = 1 - position / 15f
            page.scaleY = 1 - position / 15f
            page.translationX = (0 - position) * width
            page.alpha =  1 - position / 15f
        } else { // (1,+Infinity]
            page.scaleX = defaultScale
            page.scaleY = defaultScale
            page.translationX = -width
            page.alpha = defaultScale
        }

    }

}